<template>
  <dt-modal-edit ref="edit" title="任务生成及扣分规则批量设置" :width="700" @ok="onOk" @cancelData="hide">
    <div class="downBox">
      <span class="tips">
        <Icon type="md-alert" class="tips_icon" />
        提示：您可对任务“生成”或“扣分”进行批量操作。设置后，将对当前事业部下的所有组织生效
      </span>
      <p class="taskName">
        <span>任务名称：</span>
        <span>{{ currentRow.sopName }}</span>
      </p>
      <div class="conpany_sop_edit">
        <div class="taskSwitch" v-if="currentRow.type != 3">
          <span>任务是否生成</span>
          <i-switch @on-change="changeTaskSwitch" v-model="isTaskAssess"></i-switch>
        </div>
        <div class="taskSwitch">
          <span>任务是否扣分</span>
          <i-switch v-model="isAssess" :disabled="currentRow.type != 3 && isTaskAssess == false"></i-switch>
        </div>
      </div>
    </div>
  </dt-modal-edit>
</template>

<script>
  import sopApi from '@/biz/buildingManagement/sopConfig'
  export default {
    data() {
      return {
        isTaskAssess: false,
        isAssess: false,
        currentOrgId: '',
        currentRow: {}
      }
    },
    methods: {
      changeTaskSwitch(data) {
        if (!this.isTaskAssess) {
          this.isAssess = false
        }
      },

      onOk() {
        let params = {
          configId: this.currentRow.id,
          isAssess: this.isAssess,
          isTaskAssess: this.isTaskAssess,
          orgId: this.currentOrgId,
          updateAll: true
        }
        sopApi
          .updateOrg(params)
          .then((res) => {
            this.$emit('success')
            this.$refs.edit.hide()
          })
          .catch(() => {})
      },

      show(val, val1) {
        console.log(val, val1, 'value')
        this.currentOrgId = val
        this.currentRow = val1
        this.isTaskAssess = false
        this.isAssess = false
        this.$refs.edit.show()
      },
      hide() {}
    }
  }
</script>

<style lang="scss" scoped>
  .downBox {
    border: 1px solid #e8e8e8;
    padding: 20px;
    margin-top: 10px;
  }

  .taskName {
    margin-top: 30px;
  }

  .tips {
    text-align: right;
    line-height: 32px;
    font-size: 14px;
    background: rgba(254, 252, 236, 1);

    .tips_icon {
      font-size: 20px;
      color: #0f42a7;
      vertical-align: sub;
    }
  }

  .conpany_sop_edit {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    width: 60%;
    padding: 30px 0;

    .taskSwitch {
      display: flex;
      flex-direction: row;
      justify-content: space-around;

      span {
        margin-right: 5px;
      }
    }
  }
</style>
